import { PayloadAction, createSlice } from "@reduxjs/toolkit";
import { produce } from "immer";


export type CustomerInfoType = {
    head:string
    nickname:string
    chatid:string
}

const CustomerInfoInitial:CustomerInfoType = {
    head:'',
    nickname:'',
    chatid:''
}

const CustomerInfoSlice = createSlice({
    name:'CustomerSlice',
    initialState:CustomerInfoInitial,
    reducers:{
        setCustomerInfo:produce((draft:CustomerInfoType,action:PayloadAction<CustomerInfoType>)=>{
            for(let key in action.payload){
                if(action.payload.head === null){
                    draft['head'] = ``
                }
                draft[key] = action.payload[key]
            }
        })
    }
})

export const {setCustomerInfo} = CustomerInfoSlice.actions

export default CustomerInfoSlice.reducer